package com.portal.common.thread.example.part4;

public class ThreadWaitNotify {
    public static void main(String[] args) {
        Object lock = new Object();
        new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("1、开始点餐。。。");
                synchronized (lock){
                    try {
                        lock.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                System.out.println("3、开始食用。。。");
            }
        }, "顾客线程===>").start();
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("2、开始炒菜。。。");
                synchronized (lock){
                    lock.notify();
                }
            }
        }, "厨师线程===>").start();
    }

}
